
clear

cd "D:\data_replication"

import delimited estimation\4_demand_estimation\pc8plus_i_k.csv, clear 
keep v1 v3
rename v1 product_id
rename v3 k
save data\intermediates\pc8plus_i_k.dta, replace


use data\intermediates\intermediate_product_id.dta, clear
merge 1:1 product_id using data\intermediates\pc8plus_i_k.dta
keep k intermediate_product_id intermediate_cons_product_id
drop if k == 0
drop if k == .
order k intermediate_product_id intermediate_cons_product_id
sort k
rename intermediate_product_id intermediate_k
rename intermediate_cons_product_id intermediate_cons_k
save data\intermediates\intermediate_k.dta, replace
export delimited using data\intermediates\intermediate_k.csv, replace


import delimited estimation\5_supply_side\k_to_i_k.csv, clear
save data\intermediates\k_to_i_k.dta, replace

use data\intermediates\intermediate_k.dta, clear
merge 1:1 k using data\intermediates\k_to_i_k.dta
drop k _merge
rename intermediate_k intermediate_i_k
rename intermediate_cons_k intermediate_cons_i_k
sort i_k
order i_k intermediate_i_k intermediate_cons_i_k
save data\intermediates\intermediate_i_k.dta, replace
export delimited using data\intermediates\intermediate_i_k.csv, replace


rm data\intermediates\pc8plus_i_k.dta
rm data\intermediates\k_to_i_k.dta

